//
//  OAFlashViewController.m
//  LongOA
//
//  Created by 梁文朗 on 15/7/20.
//  Copyright (c) 2015年 梁文朗. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "OAFlashViewController.h"
#import "AppDelegate.h"
#import "OAacountSetViewController.h"
#import "OALoginViewController.h"
#import "OAAccount.h"
#import "OAEmailViewController.h"

@interface OAFlashViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *oaLogo;
@property (weak, nonatomic) IBOutlet UIImageView *ljLogo;

@end

@implementation OAFlashViewController

- (void)ChangeRoot {
    AppDelegate* delegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
    
    UIViewController* curview;
    
    if ([OAIpdataBase getIpandPortData].count>0) {
       
    }
    else
    {
        
    }
    
    [delegate.window addSubview:curview.view];
    [self.view removeFromSuperview];
    delegate.window.rootViewController = curview;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    NSLog(@"FlashLoad");

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
        OAIpdataBase* dbcache = [OAIpdataBase shareInstance];
        // TODO:获取所有缓存账套
        [dbcache initAccounts];

        dispatch_async(dispatch_get_main_queue(), ^{
            NSArray* accounts = [dbcache allAccounts];
            NSArray* loginAccouts = [dbcache loginAccounts];
            //NSLog(@"ok=%@",accounts);
            AppDelegate*app=APPDELEGATE;
            if (loginAccouts.count > 0)
            {

                // 打开主界面
                OAIndexViewController*indexVc=[[OAIndexViewController alloc]init];
                [self.view removeFromSuperview];
                //OAEmailViewController* indexVc=[[OAEmailViewController alloc] init];
                app.window.rootViewController=indexVc;
            }
            else if (accounts.count > 0)
            {
                // 打开服务器设置界面
                OAacountSetViewController*acountVc=[[OAacountSetViewController alloc]init];

                //OAEmailViewController* acountVc=[[OAEmailViewController alloc] init];
                UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:acountVc];
                nav.navigationBarHidden=YES;
                app.window.rootViewController = nav;
            }
            else
            {
                // 打开服务器设置界面并打开添加服务器窗口
                OALoginViewController*loginVc=[[OALoginViewController alloc]init];
                UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:loginVc];
                nav.navigationBarHidden=YES;
                app.window.rootViewController = nav;
            }
        });
    });
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    NSLog(@"flash dispose");
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
